<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>六西格玛知识管理</title>
<link href="<?php echo $this->baseUrl ?>/public/style/style.css" rel="stylesheet" type="text/css" />
<link href="<?php echo $this->baseUrl ?>/public/style/form-check.css" rel="stylesheet" type="text/css" />
<link href="<?php echo $this->baseUrl ?>/public/style/daterangepicker.css" rel="stylesheet" type="text/css" />
<link href="<?php echo $this->baseUrl ?>/public/style/jquery-ui.css" rel="stylesheet" type="text/css" />
<link href="<?php echo $this->baseUrl ?>/public/style/thickbox.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<?php echo $this->baseUrl ?>/public/scripts/jquery.js"></script>
<script type="text/javascript" src="<?php echo $this->baseUrl ?>/public/scripts/daterangepicker.js"></script>
<script type="text/javascript" src="<?php echo $this->baseUrl ?>/public/scripts/jquery-ui.js"></script>
<script type="text/javascript" src="<?php echo $this->baseUrl ?>/public/scripts/thickbox-compressed.js"></script>
<script type="text/javascript" src="<?php echo $this->baseUrl ?>/public/scripts/jQuery.FormValidator.js"></script>
<script type="text/javascript" src="<?php echo $this->baseUrl ?>/public/fckeditor/fckeditor.js"></script>
<script type="text/javascript" src="<?php echo $this->baseUrl ?>/public/scripts/jQuery.FormValidator.js"></script>
</head>

<body>
<!--头部-->
<?php echo $this->partial('common/header.html', array('template'=>$this->template, 'baseUrl'=>$this->baseUrl)) ?>

<!--主体-->
<div class="main-box" id="mainBox">
	<div class="third-menu">
        <?php echo $this->partial('common/operation.html', array('template'=>$this->template, 'baseUrl'=>$this->baseUrl, 'id'=>$_GET['class_id'])) ?>
		<div class="menu-title"><span class="icon"></span>设置班级阶段</div>
	</div>
  
	<div class="separate-line"></div>
	<div class="main-form">
    	<div class="project-show">
            <h2 class="project-title"><?php echo $this->class[0]['name']; ?></h2>
    	</div>
        <?php
        	$count_mission = $this->missions?count($this->missions):0;
            $current_mission = (isset($_GET['num'])&&$count_mission<=$_GET['num'])?$_GET['num']:$count_mission;
            $diff_num = $current_mission - $count_mission;
            if($diff_num){
            	$arr_diff = range(0, $diff_num-1);
            }
        	if(isset($_GET['num'])){
            	$mission_num = $_GET['num'];
            }elseif($count_mission){
            	$mission_num = $count_mission;
            }else{
            	$mission_num = 0;
            } 
        ?>
        <input type="hidden" name="class_id" value="<?php echo $_GET['class_id']; ?>" />
        <span id="mission_num_span" style="display:none"><?php echo $mission_num; ?></span>
        <p>
            <label for="mission_num">班级阶段数：</label>
            <select id="mission_num" name="mission_num" class="input-text" style="width:100px;">
                <option>请选择...</option>
                <option <?php if($mission_num==1): ?>selected<?php endif; ?> <?php if($mission_num>1): ?>class="lt_mission"<?php endif; ?>>1</option>
                <option <?php if($mission_num==2): ?>selected<?php endif; ?> <?php if($mission_num>2): ?>class="lt_mission"<?php endif; ?>>2</option>
                <option <?php if($mission_num==3): ?>selected<?php endif; ?> <?php if($mission_num>3): ?>class="lt_mission"<?php endif; ?>>3</option>
                <option <?php if($mission_num==4): ?>selected<?php endif; ?> <?php if($mission_num>4): ?>class="lt_mission"<?php endif; ?>>4</option>
                <option <?php if($mission_num==5): ?>selected<?php endif; ?> <?php if($mission_num>5): ?>class="lt_mission"<?php endif; ?>>5</option>
                <option <?php if($mission_num==6): ?>selected<?php endif; ?> <?php if($mission_num>6): ?>class="lt_mission"<?php endif; ?>>6</option>
                <option <?php if($mission_num==7): ?>selected<?php endif; ?> <?php if($mission_num>7): ?>class="lt_mission"<?php endif; ?>>7</option>
                <option <?php if($mission_num==8): ?>selected<?php endif; ?> <?php if($mission_num>8): ?>class="lt_mission"<?php endif; ?>>8</option>
                <option <?php if($mission_num==9): ?>selected<?php endif; ?> <?php if($mission_num>9): ?>class="lt_mission"<?php endif; ?>>9</option>
                <option <?php if($mission_num==10): ?>selected<?php endif; ?> <?php if($mission_num>10): ?>class="lt_mission"<?php endif; ?>>10</option>
            </select>
        </p>
        <?php if ($this->missions): ?>
        <?php foreach ($this->missions as $key => $val): ?>
        <form name="form1" id="form1" method="post" action="<?php echo $this->baseUrl ?>/class/editmission">
            <p id="mission_<?php echo $val['mission_id']; ?>" class="mission mission_p">
                <label>阶段名称：</label>
                <input type="text" name="name" class="input-text" value="<?php echo !empty($val['mission_name'])?$val['mission_name']:''; ?>" />
                <label>开始时间：</label>
                <input type="text" name="start_time" class="input-text start_time" value="<?php echo !empty($val['start_time'])?$val['start_time']:''; ?>" />
                <label>结束时间：</label>
                <input type="text" name="end_time" class="input-text" value="<?php echo !empty($val['end_time'])?$val['end_time']:''; ?>" /><br />
                <label>阶段描述：</label>
                <textarea name="remark" class="input-text" style="width:547px;"><?php echo !empty($val['remark'])?$val['remark']:''; ?></textarea>
                <input type="submit" value="修改此阶段" class="button edit_button" />
                <input type="button" value="删除此阶段" class="button del_button" />
                <input type="hidden" name="mission_id" value="<?php echo !empty($val['id'])? $val['id']:'' ?>" />
                <input type="hidden" name="class_id" value="<?php echo $_GET['class_id'] ?>" />
            </p>
        </form>
        <?php endforeach; ?>
        <?php endif; ?>
        <?php if ($arr_diff): ?>
        <form name="form1" id="form1" method="post" action="<?php echo $this->baseUrl ?>/class/addmission">
        <?php foreach ($arr_diff as $key => $val): ?>
            <p>
                <label>阶段名称：</label>
                <input type="text" name="name[]" class="input-text mission_name" />
                <label>开始时间：</label>
                <input type="text" name="start_time[]" class="input-text" />
                <label>结束时间：</label>
                <input type="text" name="end_time[]" class="input-text" /><br />
                <label>阶段描述：</label>
                <textarea name="remark[]" class="input-text" style="width:751px;"></textarea>
                <input type="hidden" name="class_id" value="<?php echo $_GET['class_id'] ?>" />
            </p>  
        <?php endforeach; ?>
        <p><label>&nbsp;</label><input type="submit" id="add_submit" class="button" style="margin-left:0" value="提 交" /></p>
        </form>
        <?php endif; ?>
	</div>
</div>
<script>
$(document).ready(function(){
	var mission_num = $("#mission_num_span").text();
	$(".del_button").hover(
		function(){
			$(".mission").removeClass("mission_p_hover");
			$(this).parent("p").addClass("mission_p_hover");
		},
		function(){
			$(".mission").removeClass("mission_p_hover");
		}
	);
	$(".edit_button").hover(
		function(){
			$(".mission").removeClass("mission_p_hover");
			$(this).parent("p").addClass("mission_p_hover");
		},
		function(){
			$(".mission").removeClass("mission_p_hover");
		}
	);
	$(".del_button").click(function(){
		var tmp = confirm('您确定要删除此阶段吗？');
		if (tmp) {
			var mission_id = $(this).next("input").val();
			var objButton = $(this);
			$.ajax({
				type: "POST",
				url: "<?php echo $this->baseUrl ?>/class/delmission",
				data: "class_id=<?php echo $_GET['class_id'] ?>&mission_id="+mission_id,
				success: function(msg){
					if(msg){
						objButton.parent("p").slideUp("slow");
						mission_num--;
						$("#mission_num_span").text(mission_num);
						$("#mission_num").val(mission_num);
						objButton.parent("p").empty();
					}else{
						alert('删除失败');
					}
				}
			}); 
		}else{
			return false;
		}
	});
	$(".lt_mission").click(function(){
		//alert('您选择的阶段数小于现有阶段数，请删除指定的班级阶段。');
		//$("#mission_num").val(mission_num);
	});
	$("#mission_num").change(function(){
		window.location.href='mission?class_id='+<?php echo $_GET['class_id'] ?>+'&num='+$(this).val();
	});
	$("#add_submit").click(function(){
		submit_result = true;
		$(".mission_name").each(function(){
			if($(this).val()==''){
				alert('班级阶段名称必填');
				submit_result = false;
				return false;
			}
		});
		return submit_result;
	});
});
</script>

<!--底部-->
<?php echo $this->partial('common/footer.html') ?>
</body>
</html>
